using System.Threading;
using System.Threading.Tasks;
using MediatR;
using B.S.BasicData.EroorCode;
using B.S.BasicData.ApiRead;
using B.S.BasicData.Domain;
using B.S.BasicData.Infrature;

public class BreedingInfoDtoGetByIdHandler : IRequestHandler<BreedingInfoDtoGetByIdRequest, ApiResult<BreedingInfoDto>>
{
    private readonly IBaseRepository<BreedingInfo> _repository;
    public BreedingInfoDtoGetByIdHandler(IBaseRepository<BreedingInfo> repository)
    {
        _repository = repository;
    }

    public async Task<ApiResult<BreedingInfoDto>> Handle(BreedingInfoDtoGetByIdRequest request, CancellationToken cancellationToken)
    {
        var entity = await _repository.GetByIdAsync(request.Id);
        if (entity == null)
            return ApiResult<BreedingInfoDto>.Fail("未找到数据");
        var dto = new BreedingInfoDto
        {
            Id = entity.Id,
            Breed = entity.Breed,
            Source = entity.Source,
            FeedingDays = entity.FeedingDays,
            FeedingBrand = entity.FeedingBrand,
            FeedingManager = entity.FeedingManager,
            OutboundDate = entity.OutboundDate,
            BatchNo = entity.BatchNo
        };
        return ApiResult<BreedingInfoDto>.Success(dto, "查询成功");
    }
} 